﻿using FTBS.Models.DAO;
using FTBS.Models.Entities;
using FTBS.Models.Entities.Concert;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FTBS.Models.BLO
{
    public class ScheduleBLO
    {
        private ScheduleDAO _scheduleDao = new ScheduleDAO();

        #region --- Booking Ticket ---

        public IEnumerable<Schedule> GetListSchedule()
        {
            return _scheduleDao.GetListShedule();
        }

        //public List<SearchSchedule> GetListScheduleForSearch()
        //{
        //    return _scheduleDao.GetListScheduleForSearch();
        //}

        /// <summary>
        /// Get list films are showing based on FilmId in Schedule table
        /// This function is used to load all film in the first time
        /// </summary>
        /// <author>vuongvt</author>
        /// <date>2014/03/02</date>
        public List<Film> GetListOfFilmShowing()
        {
            return _scheduleDao.GetListOfFilmShowing();
        }

        /// <summary>
        /// Get list theater of film by filmId
        /// -> Use when user click to a film. Load all theater are showing for this film
        /// </summary>
        /// <param name="filmId">filmId in Schedule table</param>
        /// <returns>list of theater</returns>
        /// <author>vuongvt</author>
        /// <date>2014/03/02</date>
        public List<Theater> GetListTheaterWhenChooseFilm(int filmId)
        {
            return _scheduleDao.GetListTheaterWhenChooseFilm(filmId);
        }

        /// <summary>
        /// Get list ShowTime by ShowtimeId in Schedule table
        /// -> Use when user click to a theater. Load all showtime for this a film of this theater
        /// </summary>
        /// <param name="showtimeId"></param>
        /// <returns>List of showtime</returns>
        /// <author>vuongvt</author>
        /// <date>2014/03/02</date>
        public List<ShowTime> GetListShowTimeWhenChooseTheater(int theaterId, int filmId)
        {
            return _scheduleDao.GetListShowTimeWhenChooseTheater(theaterId, filmId);
        }

        /// <summary>
        /// Get room Id to select a room for booking ticket
        /// </summary>
        /// <param name="searchSchedule"></param>
        /// <returns>RoomId</returns>
        public int GetRoomIdForBooking(SearchSchedule searchSchedule)
        {
            return _scheduleDao.GetRoomIdForBooking(searchSchedule);
        }

        /// <summary>
        /// Get ScheduleId base on FilmId, RoomId, ShowTimeId, TheaterId
        /// </summary>
        /// <param name="filmId"></param>
        /// <param name="roomId"></param>
        /// <param name="showtimeId"></param>
        /// <param name="theaterId"></param>
        /// <returns>ScheduleId</returns>
        /// <author>vuongvt</author>
        public int GetScheduleId(int filmId, int roomId, int showtimeId, int theaterId)
        {
            return _scheduleDao.GetScheduleId(filmId, roomId, showtimeId, theaterId);
        }

        /// <summary>
        /// Get user's information by username
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public User GetUserInfoByUserName(string userName)
        {
            return _scheduleDao.GetUserInfoByUserName(userName);
        }

        #endregion


        #region "Manage Schedule"

        /// <summary>
        /// Get all schedule information to load to list schedule
        /// </summary>
        /// <returns></returns>
        public List<ScheduleConcertEntity> GetAllScheduleInfo()
        {
            return _scheduleDao.GetAllScheduleInfo();
        }

        public Schedule GetScheduleById(int scheduleId)
        {
            return _scheduleDao.GetScheduleById(scheduleId);
        }

        /// <summary>
        /// Add new a schedule into Schedule table
        /// </summary>
        /// <param name="scheduleConcertEntity"></param>
        /// <returns>true: Success, false: Fail</returns>
        /// <author>vuongvt</author>
        /// <date>2014/03/04</date>
        public bool CreateSchedule(Schedule schedule)
        {
            var result = _scheduleDao.CreateSchedule(schedule);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Edit a schedule
        /// </summary>
        /// <param name="scheduleConcertEntity"></param>
        /// <returns>true: Success, false: Fail</returns>
        /// <author>vuongvt</author>
        /// <date>2014/03/04</date>
        public bool EditSchedule(Schedule schedule)
        {
            var result = _scheduleDao.EditSchedule(schedule);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Delete a schedule
        /// </summary>
        /// <param name="scheduleConcertEntity"></param>
        /// <returns>true: Success, false: Fail</returns>
        /// <author>vuongvt</author>
        /// <date>2014/03/04</date>
        public bool DeleteSchedule(Schedule schedule)
        {
            var result = _scheduleDao.DeleteSchedule(schedule);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        #endregion

        #region ---Load Films---
        /// <summary>
        /// LoadFilm in Next 7 Days
        /// </summary>
        /// <returns>ListFilm</returns>
        /// <author>nguyenht</author>
        /// <date>2014/03/06</date>
        public List<Film> LoadFilmsIn7days()
        {
            return _scheduleDao.LoadFilmsCommingSoon();
        }
        
        /// <summary>
        /// Load all films are showing in Schedule
        /// </summary>
        /// <returns></returns>
        public List<Film> GetFilmsShowing()
        {
            return _scheduleDao.LoadFilmsShowing();
        }

        /// <summary>
        /// Load all films have promotion
        /// </summary>
        /// <returns></returns>
        public List<Film> GetFilmsPromotion()
        {
            return _scheduleDao.LoadFilmsPromotion();
        }

        public Film GetFilmsBestPromtion()
        {
            return _scheduleDao.BestPromtion();
        }

        #endregion
    }
}